package com.dmgis.qxfw.dataservice.businessservice.yydl.controller;

import com.dmgis.qxfw.dataservice.businessservice.common.entity.ImportantWeather;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.SmallWindow;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.Warning;
import com.dmgis.qxfw.dataservice.businessservice.common.util.DateTime;
import com.dmgis.qxfw.dataservice.businessservice.yydl.service.SmallWindowServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/xtdl")
public class SmallWindowController {
	@Autowired
	private SmallWindowServiceI smallServiceImpl;
	@RequestMapping("/importWtTipInfo")
	@ResponseBody
	public List<ImportantWeather> importWtTipInfo(){
		DateTime dt = DateTime.now();
		String date = dt.toDateString() + " 00:00:00";
		String date1 = dt.toDateString() + " 23:59:00";
		List<SmallWindow> list1 = new ArrayList<SmallWindow>();
		list1 = smallServiceImpl.getImpWtInfoTip(date, date1);
		List<ImportantWeather> listResult = new ArrayList<ImportantWeather>();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		if(list1!=null){
			for(SmallWindow s : list1){
				ImportantWeather iw = new ImportantWeather();
				iw.setStationId(s.getStationId());
				iw.setStationName(s.getStationName());
				String format1 = format.format(s.getObserveTime());
				iw.setObservTime(format1);
				iw.setType(s.getForecastClass());
				iw.setDetail(s.getForecastInfo());
				listResult.add(iw);
			}
		}
		return listResult;
	}
	
	@RequestMapping("/warningInfoTip")
	@ResponseBody
	public String warningInfoTip(){
		String temp = "[";
		DateTime dt = DateTime.now();
		String str1 = dt.AddDays(-1).toDateTimeString();
		String str2 = dt.toDateTimeString();
		List<Warning> list = new ArrayList<Warning>();
		list = smallServiceImpl.warningInfoTip(str1, str2);
		if(list!=null){
			for(Warning w : list){
				temp += "{";
                temp += "\"Type\":\"" + w.getType() + "\",";
                temp += "\"Color\":\"" + w.getColor() + "\",";
                temp += "\"County\":\"" + w.getCounty() + "\"";
                temp += "},";
			}
		}
		if(temp.endsWith(",")){
			temp = temp.substring(0, temp.length()-1);
		}
		temp = temp + "]";
		
		return temp;
	}

}
